<template>
  <div class="container">
    <div class="header">
      <el-input class="input" v-model="username" placeholder="请输入用户ID"></el-input>
      <el-input class="input" v-model="mobile" placeholder="请输入收货人名称"></el-input>
      <el-button class="btn" type="primary" icon="el-icon-search">查找</el-button>
      <el-button class="btn" type="primary" icon="el-icon-download">导出</el-button>
    </div>

    <div class="table-box">
      <el-table :data="tableData" border style="width: 100%;">
        <el-table-column prop="addressId" label="地址ID" width="180" align="center">
        </el-table-column>
        <el-table-column prop="userId" label="用户ID" width="180" align="center">
        </el-table-column>
        <el-table-column prop="username" label="收货人名称" width="180" align="center">
        </el-table-column>
        <el-table-column prop="mobile" label="手机号码" align="center">
        </el-table-column>
        <el-table-column prop="addressDetail" label="地址" align="center">
        </el-table-column>
        <el-table-column prop="isDefault" label="默认" align="center">
        </el-table-column>
        
      </el-table>
    </div>
  </div>
</template>

<script>

import { getAddressData } from '../../api/user-manage'
import { getToken } from '@/utils/auth'


export default {
  name: 'address',
  data() {
    return {
      username: '',
      mobile: '',
      // tableData: [{
      //   date: '2016-05-02',
      //   name: '王小虎',
      //   address: '上海市普陀区金沙江路 1518 弄'
      // }, {
      //   date: '2016-05-04',
      //   name: '王小虎',
      //   address: '上海市普陀区金沙江路 1517 弄'
      // }, {
      //   date: '2016-05-01',
      //   name: '王小虎',
      //   address: '上海市普陀区金沙江路 1519 弄'
      // }, {
      //   date: '2016-05-03',
      //   name: '王小虎',
      //   address: '上海市普陀区金沙江路 1516 弄'
      // }],
      tableData: []

    }
  },
  mounted() {
    getAddressData().then(res => {
      console.log(res);
      let { data, errno } = res;
      if (errno == 0) {
        data.items.forEach(item => {
          this.tableData.push({
            addressId:item.id,
            userId: item.userId,
            username: item.name,
            mobile: item.mobile,
            addressDetail: item.province+item.city+item.area+item.address,
            isDefault:item.isDefault?'是':'否',
          })
        })
      }
    })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.container {
  padding: 20px;

  .header {
    .input {
      width: 200px;
      margin-right: 5px;
    }
  }


  .table-box {
    width: 100%;
    margin-top: 30px;
  }

}
</style>